import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,AlertController} from 'ionic-angular';
import {UserService} from "../../providers/UserService";
import {USERFACE_PATH} from "../../providers/Constants";
import {UserInfo} from "../../model/UserInfo";
import {StorageService} from "../../providers/StorageService";
import {BaseUI} from "../../common/baseui";

@IonicPage()
@Component({
  selector: 'page-join-sport-person',
  templateUrl: 'join-sport-person.html',
})
export class JoinSportPersonPage extends BaseUI{

  sportId:any;
  userList:any;
  userFacePath:string;

  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public  userService:UserService,
              public storageService:StorageService,
              public alertCtrl:AlertController) {

    super();
    this.userFacePath = USERFACE_PATH;

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad JoinSportPersonPage');
    this.sportId = this.navParams.get("sportId");
    this.getJoinSportUserList(this.sportId);
  }

  getJoinSportUserList(sportId){
    this.userService.selectJoinSportPerson(sportId).subscribe(res=>{
      this.userList = res["data"];
    })
  }

  //聊天
  opneChatDetail(userId,nickName,userFace){
    var user = this.storageService.read<UserInfo>('UserInfo');
    if(userId!=undefined && userId ==user.id){
      super.showAlert(this.alertCtrl,null,'抱歉，不能向自己发起会话','确定');
      return;
    }
    this.navCtrl.push("ChatdetailPage",{chatUserNickName:nickName,
      chatUserFace:userFace,
      chatUserPhone:userId});
  }

}
